1 Load libraries and source code

# devtools::install_github('EcologicalTraitData/traitdataform')

rm(list=ls())

list.of.packages <- c("ggplot2","data.table","dplyr","tidyr","parallel","bdc","taxadb","traitdataform","pbapply","tidyverse","readxl","lme4","coefplot","sjPlot","sjmisc","effects","rgdal","maptools","rgeos","terra","MuMIn","rnaturalearthdata","lsmeans","GGally","tidyterra","httr","purrr","rlist","usethis")

new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]

if(length(new.packages)) install.packages(new.packages)

sapply(list.of.packages, require, character.only = TRUE)
## Warning: package 'terra' was built under R version 4.3.2
##           ggplot2        data.table             dplyr             tidyr 
##              TRUE              TRUE              TRUE              TRUE 
##          parallel               bdc            taxadb     traitdataform 
##              TRUE              TRUE              TRUE              TRUE 
##           pbapply         tidyverse            readxl              lme4 
##              TRUE              TRUE              TRUE              TRUE 
##          coefplot            sjPlot            sjmisc           effects 
##              TRUE              TRUE              TRUE              TRUE 
##             rgdal          maptools             rgeos             terra 
##              TRUE              TRUE              TRUE              TRUE 
##             MuMIn rnaturalearthdata           lsmeans            GGally 
##              TRUE              TRUE              TRUE              TRUE 
##         tidyterra              httr             purrr             rlist 
##              TRUE              TRUE              TRUE              TRUE 
##           usethis 
##              TRUE

2 source functions

# Code to find accepted species names
# Before you can download the source code from github, make sure you have a personal github token
# run this:
# usethis::edit_r_environ()
# if you have no toke, create one following:
# 1. Generate on GitHub your personal token
# 1.1 Go to GitHub
# 2.1 In the right corner go to "Settings"
# 2.2 Then in the left part go to "Developer setting"
# 2.3 Select the option "Personal access tokens"
# 2.4 Select the option "Generate new token"
# 2.5 Copy your personal token
# run this to add the token to your .Renviron
# usethis::edit_r_environ()
# write GITHUB_PAT=YOUR_TOKEN
# Sys.getenv("GITHUB_PAT")

source(here::here("R/fetchGHdata.R"))

fetchGHdata(gh_account = "Bioshifts", 
            repo = "bioshifts_v1_v2", 
            path = "R/Source_code/Clean_names.R",
            output = here::here("R/Clean_names.R"))
## Loading required package: jsonlite
## 
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
## 
##     flatten
## [1] 0
fetchGHdata(gh_account = "Bioshifts", 
            repo = "bioshifts_v1_v2", 
            path = "R/Source_code/Find_Sci_Names.R",
            output = here::here("R/Find_Sci_Names.R"))
## [1] 0
source(here::here("R/Clean_names.R"))
source(here::here("R/Find_Sci_Names.R"))

# Malin's transformation for moving values slightly inward. 
transform01 <- function(x) (x * (length(x) - 1) + 0.5) / (length(x))

# De Kort transformation
deKort_trans <- function(p){
    p <- scale(p)
    p <- (p - min(p, na.rm = T))/(max(p, na.rm = T)-min(p, na.rm = T))
    return(p)
}

# Malin's transformation before a logit transformation
logit_trans <- function(p){
    p <- transform01(p)
    p <- log(p/(1-p))
    return(p)
}

3 Load species list

splist <- read.csv(here::here("Data/splist.csv"), header = T)

# remove duplicated sp_names
splist <- splist %>%
    dplyr::filter(!duplicated(scientificName))%>%
    mutate(Kingdom=kingdom,
           Phylum=phylum,
           Class=class,
           Order=order,
           Family=family)%>%
    dplyr::select(scientificName,Kingdom,Phylum,Class,Order,Family,db)

splist$Genus <- sapply(splist$scientificName, function(x){
    strsplit(x," ")[[1]][1]
})

4 Load bioshifts

4.1 Load v1

biov1 <- read.csv(here::here("Data/biov1_fixednames.csv"), header = T)

# Fix references in biov1
biov1$sp_name_std_v1 <- gsub("_"," ",biov1$sp_name_std_v1)
biov1 <- biov1 %>%
    dplyr::select(ID,Article_ID,Study_ID,
                  Type,Param,Trend,SHIFT,UNIT,DUR,
                  v.lat.mean,v.ele.mean,
                  START,END,Sampling,Uncertainty_Distribution,Uncertainty_Parameter,
                  N,Grain_size,Data,ID.area,
                  Phylum,Class,Order,Family,Genus,sp_name_std_v1,
                  group,ECO,Hemisphere) %>% # select columns
    mutate(
        Type = case_when(
            Type=="HOR" ~ "LAT",
            TRUE ~ as.character(Type)),
        Data = case_when(
            Data=="occurence-based" ~ "occurrence-based",
            TRUE ~ as.character(Data)),
        spp = sp_name_std_v1,
        SHIFT_abs = abs(SHIFT),
        velocity = ifelse(Type == "LAT", v.lat.mean, v.ele.mean),
        vel_sign = ifelse(velocity>0,"pos","neg"))

biov1 <- biov1 %>%
    dplyr::filter(!is.na(sp_name_std_v1))

all(biov1$sp_name_std_v1 %in% splist$scientificName)
## [1] TRUE
# from continuous to categorical
q1=quantile(biov1$START,probs=c(0,0.25,0.5,0.75,1))
biov1$StartF=cut(biov1$START,breaks=q1,include.lowest=T)

q1=quantile(biov1$ID.area,probs=c(0,0.25,0.5,0.75,1))
biov1$AreaF=cut(biov1$ID.area,breaks=q1,include.lowest=T)

q1=quantile(biov1$N,probs=c(0,0.25,0.5,0.75,1))
biov1$NtaxaF=cut(biov1$N,breaks=q1,include.lowest=T)

# add ID to obs
biov1$obs_ID <- paste0("S",1:nrow(biov1))


summary(biov1$velocity)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
## -5.8328  0.5415  1.9642  2.2635  2.7543 14.5492    1450
summary(biov1$velocity[which(biov1$vel_sign=="pos")])
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
##  0.009396  0.541507  2.055833  2.411912  2.831932 14.549230

4.2 Classify species

# Class species as Terrestrial, Marine or Freshwater
Terv1 <- unique(biov1$sp_name_std_v1[which(biov1$ECO == "T")])
Terrestrials = unique(c(Terv1))

Mar1 <- unique(biov1$sp_name_std_v1[which(biov1$ECO == "M")])
Marine = unique(c(Mar1))

# Freshwater fish
FFishv1 <- unique(biov1$sp_name_std_v1[(biov1$Class == "Actinopterygii" | biov1$Class == "Cephalaspidomorphi") & biov1$ECO == "T"])
FFish = unique(c(FFishv1))
# Marine fish
MFishv1 <- unique(biov1$sp_name_std_v1[biov1$Class == "Actinopterygii" & biov1$ECO == "M"])
MFish = unique(c(MFishv1))

splist$ECO = NA
splist$ECO[which(splist$scientificName %in% Terrestrials)] <- "T"
splist$ECO[which(splist$scientificName %in% Marine)] <- "M"
splist$ECO[which(splist$scientificName %in% MFish)] <- "M"

biov1$ECO = NA
biov1$ECO[which(biov1$sp_name_std_v1 %in% Terrestrials)] <- "T"
biov1$ECO[which(biov1$sp_name_std_v1 %in% Marine)] <- "M"
biov1$ECO[which(biov1$sp_name_std_v1 %in% MFish)] <- "M"

splist$Group = NA
splist$Group[which(splist$Class == "Phaeophyceae")] <- "Chromista"
splist$Kingdom[which(splist$Class == "Phaeophyceae")] <- "Chromista"
splist$Group[which(splist$Phylum == "Rhodophyta")] <- "Seaweed"
splist$Kingdom[which(splist$Phylum == "Rhodophyta")] <- "Plantae"
splist$Group[which(splist$Family == "Elminiidae")] <- "Barnacles"
splist$Group[which(splist$Kingdom == "Bacteria")] <- "Bacteria"
splist$Group[which(splist$Class == "Holothuroidea")] <- "Sea cucumber"
splist$Group[which(splist$Class == "Aves")] <- "Bird"
splist$Group[which(splist$Class == "Insecta")] <- "Insect"
splist$Group[which(splist$Class == "Mammalia")] <- "Mammal"
splist$Group[which(splist$Class == "Arachnida")] <- "Spider"
splist$Kingdom[which(splist$Kingdom == "Viridiplantae")] <- "Plantae"
splist$Kingdom[which(splist$Phylum == "Tracheophyta")] <- "Plantae"
splist$Group[which(splist$Kingdom == "Plantae")] <- "Plant"
splist$Group[which(splist$Class == "Hydrozoa")] <- "Hydrozoa"
splist$Group[which(splist$Class == "Anthozoa")] <- "Sea anemones and corals"
splist$Group[which(splist$Class == "Polychaeta")] <- "Polychaetes"
splist$Group[which(splist$Phylum == "Mollusca")] <- "Molluscs"
splist$Group[which(splist$Class == "Malacostraca")] <- "Crustacean"
splist$Group[which(splist$Class == "Hexanauplia")] <- "Crustacean"
splist$Group[which(splist$Class == "Maxillopoda")] <- "Crustacean"
splist$Group[which(splist$Class == "Ostracoda")] <- "Crustacean"
splist$Group[which(splist$Class == "Branchiopoda")] <- "Crustacean"
splist$Group[which(splist$Class == "Asteroidea")] <- "Starfish"
splist$Group[which(splist$Class == "Ascidiacea")] <- "Ascidians tunicates and sea squirts"
splist$Class[which(splist$Class == "Actinopteri")] <- "Actinopterygii"
splist$Group[which(splist$Class == "Actinopterygii")] <- "Fish"
splist$Group[which(splist$Class == "Elasmobranchii")] <- "Fish"
splist$Group[which(splist$Order == "Perciformes")] <- "Fish"
splist$Group[which(splist$Class == "Chondrichthyes")] <- "Fish"
splist$Group[which(splist$Class == "Holocephali")] <- "Fish"
splist$Group[which(splist$Class == "Cephalaspidomorphi")] <- "Fish"
splist$Group[which(splist$Class == "Echinoidea")] <- "Sea urchin"
splist$Group[which(splist$Class == "Crinoidea")] <- "Crinoid"
splist$Group[which(splist$Class == "Holothuroidea")] <- "Sea cucumber"
splist$Group[which(splist$Class == "Reptilia")] <- "Reptile"
splist$Group[which(splist$Order == "Squamata")] <- "Reptile"
splist$Group[which(splist$Class == "Ophiuroidea")] <- "Brittle stars"
splist$Group[which(splist$Class == "Chilopoda")] <- "Centipedes"
splist$Group[which(splist$Class == "Diplopoda")] <- "Millipedes"
splist$Group[which(splist$Class == "Amphibia")] <- "Amphibian"
splist$Group[which(splist$Kingdom == "Fungi")] <- "Fungi"
splist$Group[which(splist$Order == "Balanomorpha")] <- "Barnacles"
splist$Group[which(splist$Phylum == "Nematoda")] <- "Nematodes"
splist$Group[which(splist$Class == "Myxini")] <- "Hagfish"
splist$Group[which(splist$Kingdom == "Chromista")] <- "Chromista"
splist$Family[which(splist$Genus == "Dendrocopus")] <- "Picidae"

######################################
biov1 <- merge(biov1[,-which(names(biov1) %in% c("Phylum","Class","Order","Family","Genus","Group","ECO"))], 
               splist[,c("Kingdom","Phylum","Class","Order","Family","Genus","Group","ECO","scientificName")], 
               by.x = "sp_name_std_v1", by.y = "scientificName", 
               all.x = T)

4.3 Filter LAT / ELE shifts

Use only latitudinal and elevational shifts

# v1
biov1 <- biov1 %>%
    dplyr::filter(Type %in% c("ELE","LAT"))  # Use LAT ELE shifts

# splist
sps <- unique(biov1$sp_name)
splist <- splist %>% dplyr::filter(scientificName %in% sps)

4.4 Remove species identified to the genus level or cf.

if(any(grep("sp[.]",biov1$sp_reported_name_v1))){
    biov1 <- biov1 %>% dplyr::filter(!grepl("sp[.]",sp_reported_name_v1))
}
if(any(grep("sp[.]",biov1$sp_name_std_v1))){
    biov1 <- biov1 %>% dplyr::filter(!grepl("sp[.]",sp_name_std_v1))
}
if(any(grep("cf[.]",biov1$sp_reported_name_v1))){
    biov1 <- biov1 %>% dplyr::filter(!grepl("cf[.]",sp_reported_name_v1))
}
if(any(grep("cf[.]",biov1$sp_name_std_v1))){
    biov1 <- biov1 %>% dplyr::filter(!grepl("cf[.]",sp_name_std_v1))
}

#remove freshwater fishes
biov1 <- biov1[-which((biov1$Class == "Actinopterygii" | biov1$Group == "Fish") & biov1$ECO=="T"),]

#remove marine birds
biov1 <- biov1[-which(biov1$Class == "Aves" & biov1$ECO=="M"),]


if(any(grep("sp[.]",splist$scientificName))){
    splist <- splist %>% dplyr::filter(!grepl("sp[.]",scientificName))
}
if(any(grep("sp[.]",splist$scientificName))){
    splist <- splist %>% dplyr::filter(!grepl("sp[.]",scientificName))
}
if(any(grep("cf[.]",splist$scientificName))){
    splist <- splist %>% dplyr::filter(!grepl("cf[.]",scientificName))
}
if(any(grep("cf[.]",splist$scientificName))){
    splist <- splist %>% dplyr::filter(!grepl("cf[.]",scientificName))
}

4.5 Reclassify methodological variables

unique(biov1$Data)
## [1] "abundance-based"  "occurrence-based"
biov1$Data[biov1$Data=="occurence-based"] <- "occurrence-based"
biov1$Data <- factor(biov1$Data, levels = unique(biov1$Data))
table(biov1$Data)
## 
##  abundance-based occurrence-based 
##             9496            20744
unique(biov1$Sampling)
## [1] "TWO"                  "CONTINUOUS"           "MULTIPLE(continuous)"
## [4] "IRR"
biov1$Sampling = ifelse(biov1$Sampling %in% c("IRR","MULTIPLE(continuous)"),"MULTIPLE", biov1$Sampling)
biov1$Sampling <- ordered(biov1$Sampling, 
                          levels = c("TWO","MULTIPLE","CONTINUOUS"))
table(biov1$Sampling)
## 
##        TWO   MULTIPLE CONTINUOUS 
##      25819       1251       3170
unique(biov1$Grain_size)
## [1] "small"      "large"      "moderate"   "very_large" NA
biov1$Grain_size <- ifelse(biov1$Grain_size %in% c("large","very_large"),"large",biov1$Grain_size)
biov1$Grain_size <- ordered(biov1$Grain_size, 
                            levels = c("small","moderate","large"))
table(biov1$Grain_size)
## 
##    small moderate    large 
##     9841    10971     9427
unique(biov1$Uncertainty_Distribution)
## [1] "RESAMPLING(same)"               "RAW"                           
## [3] "RESAMPLING"                     "MODEL"                         
## [5] "RESAMPLING+MODEL"               "MODEL+RESAMPLING(same)"        
## [7] "RESAMPLING(same)+DETECTABILITY" "RESAMPLING(same)+MODEL"        
## [9] "DETECTABILITY"
biov1$Uncertainty_Distribution <- ifelse(biov1$Uncertainty_Distribution %in% c("RESAMPLING","RESAMPLING(same)"),"RESAMPLING",
                                         ifelse(biov1$Uncertainty_Distribution %in% c("MODEL","MODEL+RESAMPLING(same)","RESAMPLING+MODEL"),"MODEL",
                                                ifelse(biov1$Uncertainty_Distribution %in% c("DETECTABILITY","RESAMPLING(same)+DETECTABILITY"),"DETECTABILITY",
                                                       biov1$Uncertainty_Distribution)))
biov1$Uncertainty_Distribution <- ifelse(biov1$Uncertainty_Distribution == "RAW","OPPORTUNISTIC","PROCESSED")  
table(biov1$Uncertainty_Distribution)
## 
## OPPORTUNISTIC     PROCESSED 
##          9532         20708
#transform study area
biov1$ID.area <- log(biov1$ID.area)

4.6 Get centroids of study areas

This will be used to merge genetic data with bioshifts based on distance of observations

# # The input file geodatabase
# fgdb <- "C:/Users/brunn/nextCloud/bioshifts_v1_v2/v1/Study_Areas_v1/Study_Areas.gdb"
# 
# # List all feature classes in a file geodatabase
# fc_list <- ogrListLayers(fgdb)
# 
# # Get centroids
# cl <- makeCluster(detectCores()-1)
# clusterExport(cl, c("readOGR", "gCentroid", "fgdb"))
# 
# centroids <- pblapply(fc_list, function(x){
#     fc <- readOGR(dsn=fgdb,layer=x)
#     c <- data.frame(gCentroid(fc))
#     names(c) <- c("centroid.x", "centroid.y")
# 
#     geomet <- data.frame(terra::geom(terra::vect(fc)))
# 
#     max_lat <- order(geomet[,"y"], decreasing = T)[1]
#     max_lat <- geomet[max_lat,c("x","y")]
#     names(max_lat) <- c("max_lat.x", "max_lat.y")
# 
#     min_lat <- order(geomet[,"y"])[1]
#     min_lat <- data.frame(geomet[min_lat,c("x","y")])
#     names(min_lat) <- c("min_lat.x", "min_lat.y")
# 
#     cbind(c, max_lat, min_lat)
# }, cl = cl)
# 
# stopCluster(cl)
# 
# centroids <- do.call("rbind",centroids)
# centroids$ID <- fc_list
# 
# write.csv(centroids, "Data/centroids_study_areas.csv", row.names = FALSE)

centroids <- read.csv(here::here("Data/centroids_study_areas.csv"))

biov1 <- merge(biov1, centroids, by = "ID")

5 Corrected shifts

Just load it in

fetchGHdata(gh_account = "Bioshifts", 
            repo = "MethodologicalAdjustment", 
            path = "outputs/biov1_method_corrected_shifts_study_level.csv",
            output = here::here("Data/biov1_method_corrected_shifts_study_level.csv"))
## [1] 0
biov1_corr <- read.csv(here::here("Data/biov1_method_corrected_shifts_study_level.csv"))

# add corrected shifts
biov1 <- merge(biov1, 
               biov1_corr %>%
                   select(c("Article_ID","Study_ID","Class","Type","SLDiff1")), 
               by = c("Article_ID","Study_ID","Class","Type"),
               all.x = TRUE)

biov1$SHIFT_cor <- abs(biov1$SHIFT) - biov1$SLDiff1

# change sign for negative shifts
biov1$neg_shifts <- ifelse(sign(biov1$SHIFT) == -1 & biov1$SHIFT != 0, 1, 0)

biov1$SHIFT_cor[which(biov1$neg_shifts == 1)] <- biov1$SHIFT_cor[which(biov1$neg_shifts == 1)] * -1

6 Direction of shift

Identify direction of shift

biov1 <- biov1 %>%
    mutate(shift_sign = ifelse(SHIFT>0,"pos","neg"),
           shift_vel_sign = paste0(shift_sign,vel_sign),
           shiftC_sign = ifelse(SHIFT_cor>0,"pos","neg"),
           shiftC_vel_sign = paste0(shiftC_sign,vel_sign)
    ) %>%
    filter(!is.na(velocity))

ggplot(biov1, aes(x=shift_vel_sign))+
    geom_bar()+
    coord_flip()+
    facet_wrap(Type~Param)

ggplot(biov1, aes(x=shiftC_vel_sign))+
    geom_bar()+
    coord_flip()+
    facet_wrap(Type~Param)

summary(biov1$velocity)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -5.8328  0.5415  1.9642  2.2637  2.6272 14.5492
summary(biov1$velocity[which(biov1$shift_vel_sign=="pospos")])
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
##  0.009396  0.541507  2.055833  2.464171  2.831932 14.549230
summary(biov1$velocity[which(biov1$shift_vel_sign=="negneg")])
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -3.79347 -2.30487 -1.78004 -1.59872 -0.58152 -0.02945

7 Calculate lags raw

# calculate lags
# positive values are a lag (range shift lower smaller than expected or in opposite directions) and negative values are range shift larger than expected
biov1$lag <- biov1$velocity-biov1$SHIFT
position = which(biov1$vel_sign == "neg")
biov1$lag[position] <- biov1$lag[position] * -1 # Any negative velocity means the sign of lag has to shift.

# Lag 2
# When shift is in opposite sign of velocity, lag = abs(velocity)
biov1$lag2 = biov1$lag
position <- which(biov1$shift_vel_sign == "posneg" | biov1$shift_vel_sign == "negpos")
biov1$lag2[position] <- abs(biov1$velocity[position])

# Lag 3
# When shift is > velocity, lag = 0
biov1$lag3 = biov1$lag2
position <- which((biov1$shift_sign == "pos" & biov1$SHIFT > biov1$velocity) |
                      (biov1$shift_sign == "neg" & biov1$SHIFT < biov1$velocity))
biov1$lag3[position] <- 0


{
    par(mfrow=c(2,2))
    plot(lag~velocity, biov1)
    plot(lag2~velocity, biov1)
    plot(lag3~velocity, biov1)
}

ggplot(biov1, aes(x = Param, y=lag, fill = Param, color = Param))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    scale_y_continuous(limits = quantile(biov1$lag2, c(0.1, 0.9), na.rm = T))+
    facet_wrap(.~Type, scales = "free")
## Warning: Removed 8827 rows containing non-finite values (`stat_boxplot()`).
ggplot(biov1, aes(x = Param, y=lag2, fill = Param, color = Param))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    scale_y_continuous(limits = quantile(biov1$lag2, c(0.1, 0.9), na.rm = T))+
    facet_wrap(.~Type, scales = "free")
## Warning: Removed 6044 rows containing non-finite values (`stat_boxplot()`).
ggplot(biov1, aes(x = Param, y=log1p(lag3), fill = Param, color = Param))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    # scale_y_continuous(limits = quantile(log1p(biov1$lag3), c(0.1, 0.9), na.rm = T))+
    facet_wrap(.~Type, scales = "free")

8 Calculate lags corrected

# calculate lagCs
# positive values are a lagC (range shift lower smaller than expected or in opposite directions) and negative values are range shift larger than expected
biov1$lagC <- biov1$velocity-biov1$SHIFT_cor
position = which(biov1$vel_sign == "neg")
biov1$lagC[position] <- biov1$lagC[position] * -1 # Any negative velocity means the sign of lagC has to shift.

# Lag 2
# When shift is in opposite sign of velocity, lagC == velocity
biov1$lagC2 = biov1$lagC
position <- which(biov1$shiftC_vel_sign == "posneg" | biov1$shiftC_vel_sign == "negpos")
biov1$lagC2[position] <- abs(biov1$velocity[position])

# Lag 3
# When shift is > velocity, lagC = 0
biov1$lagC3 = biov1$lagC2
position <- which((biov1$shiftC_sign == "pos" & biov1$SHIFT_cor > biov1$velocity) |
                      (biov1$shiftC_sign == "neg" & biov1$SHIFT_cor < biov1$velocity))
biov1$lagC3[position] <- 0


{
    par(mfrow=c(2,2))
    plot(lagC~velocity, biov1)
    plot(lagC2~velocity, biov1)
    plot(lagC3~velocity, biov1)
}

ggplot(biov1, aes(x = Param, y=lagC, fill = Param, color = Param))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    scale_y_continuous(limits = quantile(biov1$lagC2, c(0.1, 0.9), na.rm = T))+
    facet_wrap(.~Type, scales = "free")
## Warning: Removed 10765 rows containing non-finite values (`stat_boxplot()`).
ggplot(biov1, aes(x = Param, y=lagC2, fill = Param, color = Param))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    scale_y_continuous(limits = quantile(biov1$lagC2, c(0.1, 0.9), na.rm = T))+
    facet_wrap(.~Type, scales = "free")
## Warning: Removed 6573 rows containing non-finite values (`stat_boxplot()`).
ggplot(biov1, aes(x = Param, y=log1p(lagC3), fill = Param, color = Param))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    # scale_y_continuous(limits = quantile(log1p(biov1$lagC3), c(0.1, 0.9), na.rm = T))+
    facet_wrap(.~Type, scales = "free")
## Warning: Removed 655 rows containing non-finite values (`stat_boxplot()`).

9 Corrected vs raw shifts

plot(SHIFT_cor~SHIFT,biov1)
abline(a=0,b=1,col=2)

lm0=lm(SHIFT_cor~SHIFT,biov1)
summary(lm0)
## 
## Call:
## lm(formula = SHIFT_cor ~ SHIFT, data = biov1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.4752 -1.0085  0.1219  0.8303  3.4359 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.112782   0.007375   15.29   <2e-16 ***
## SHIFT       1.020616   0.001328  768.28   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.241 on 29582 degrees of freedom
##   (655 observations deleted due to missingness)
## Multiple R-squared:  0.9523, Adjusted R-squared:  0.9523 
## F-statistic: 5.903e+05 on 1 and 29582 DF,  p-value: < 2.2e-16
hist(biov1$SHIFT,col=rgb(1,0,0,0.5))
hist(biov1$SHIFT_cor,col=rgb(0,0,1,0.5),add=T)

#so by using residuals we decrease the variation in the raw range shift obs, it's like we work on a more homogenous variables as all the variations due to methods variation has been substracted to the shift.

x1=tapply(biov1$SHIFT,biov1$Group,mean)
x2=tapply(biov1$SHIFT_cor,biov1$Group,mean)#lower mean value than true obs 
plot(x1~x2, xlab="Mean shift per Group (raw)", ylab="Mean shift per Group (corrected)")

lm0=lm(x1~x2,biov1)
summary(lm0) #it changes many things
## 
## Call:
## lm(formula = x1 ~ x2, data = biov1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.73514 -0.03389  0.09699  0.20771  0.47424 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.50337    0.14439  -3.486  0.00824 ** 
## x2           1.01161    0.01014  99.774 1.14e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4498 on 8 degrees of freedom
##   (14 observations deleted due to missingness)
## Multiple R-squared:  0.9992, Adjusted R-squared:  0.9991 
## F-statistic:  9955 on 1 and 8 DF,  p-value: 1.137e-13
x1=tapply(biov1$SHIFT,biov1$Group,var)
x2=tapply(biov1$SHIFT_cor,biov1$Group,var)#lower variance value than in true obs 
plot(x1~x2, xlab="Variance shift per Group (raw)", ylab="Variance shift per Group (corrected)")

lm0=lm(x1~x2,biov1)
summary(lm0) #but high positive correlation meaning that relative variation is conserved
## 
## Call:
## lm(formula = x1 ~ x2, data = biov1)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -5.947 -1.086 -0.033  1.921  4.507 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.42377    1.92874  -1.257    0.256    
## x2           0.98038    0.03793  25.850 2.21e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.435 on 6 degrees of freedom
##   (16 observations deleted due to missingness)
## Multiple R-squared:  0.9911, Adjusted R-squared:  0.9896 
## F-statistic: 668.2 on 1 and 6 DF,  p-value: 2.21e-07
x1=tapply(biov1$SHIFT,biov1$sp_name_std_v1,mean)
x2=tapply(biov1$SHIFT_cor,biov1$sp_name_std_v1,mean)#lower mean value than in true obs 
plot(x1~x2, xlab="Mean shift per species (raw)", ylab="Mean shift per species (corrected)")

lm0=lm(x1~x2,biov1)
summary(lm0) #but at the species level, we observe a high positive relationship so the corrected shifts did not change the pattern of range shift=> good
## 
## Call:
## lm(formula = x1 ~ x2, data = biov1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.1326 -0.6949  0.0047  0.7381  8.5064 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.056877   0.008936  -6.365 2.03e-10 ***
## x2           0.949122   0.001570 604.366  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.938 on 11823 degrees of freedom
##   (400 observations deleted due to missingness)
## Multiple R-squared:  0.9686, Adjusted R-squared:  0.9686 
## F-statistic: 3.653e+05 on 1 and 11823 DF,  p-value: < 2.2e-16
#looking at the relationship with climate velocity
#WARNING:here you need to adapt the code: if you look at the elevational range shift so you have to use EleVeloT in order to use the corresponding climate velocity
par(mfrow=c(1,2))
plot(SHIFT~velocity, xlab="SHIFT (raw)", ylab="Velocity",biov1)
lm0=lm(SHIFT~velocity+I(velocity^2),biov1)
summary(lm0)
## 
## Call:
## lm(formula = SHIFT ~ velocity + I(velocity^2), data = biov1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -120.800   -1.647   -0.793    1.235  145.241 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    0.849723   0.049818  17.057  < 2e-16 ***
## velocity       0.196547   0.029156   6.741  1.6e-11 ***
## I(velocity^2) -0.010877   0.002899  -3.751 0.000176 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.532 on 30236 degrees of freedom
## Multiple R-squared:  0.002488,   Adjusted R-squared:  0.002422 
## F-statistic: 37.71 on 2 and 30236 DF,  p-value: < 2.2e-16
x1=seq(min(biov1$velocity,na.rm = T),max(biov1$velocity,na.rm = T),le=100)
p1=predict(lm0,newdata=data.frame(velocity=x1),type="response")
points(p1~x1,type="l",col=2,lwd=2)
plot(SHIFT_cor~velocity, xlab="SHIFT (corrected)", ylab="Velocity",biov1)#the pattern is changing a lot
lm0=lm(SHIFT_cor~velocity+I(velocity^2),biov1)
summary(lm0)
## 
## Call:
## lm(formula = SHIFT_cor ~ velocity + I(velocity^2), data = biov1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -119.895   -2.436   -0.109    1.758  144.074 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    0.936871   0.052087  17.987  < 2e-16 ***
## velocity       0.214470   0.030694   6.987 2.86e-12 ***
## I(velocity^2) -0.011038   0.003114  -3.545 0.000394 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.67 on 29581 degrees of freedom
##   (655 observations deleted due to missingness)
## Multiple R-squared:  0.003057,   Adjusted R-squared:  0.002989 
## F-statistic: 45.35 on 2 and 29581 DF,  p-value: < 2.2e-16
x1=seq(min(biov1$velocity,na.rm = T),max(biov1$velocity,na.rm = T),le=100)
p1=predict(lm0,newdata=data.frame(velocity=x1),type="response")
points(p1~x1,type="l",col=2,lwd=2)

#we observed a relationship for the raw range shift (an unimodal relationship with higher shifts when absolute climate velocity increase).
#for the range shift corrected by method, no relationship with climatic velocity is observed

#looking at the relationship with lag
par(mfrow=c(1,2))
plot(lagC~velocity,biov1,main="corrected lag estimate")
# Lag C2
# When shift is in opposite sign of velocity, lag == velocity
plot(lagC2~velocity,biov1,main="corrected lag estimate with correction for special case")

#change more things than the above lag metrics, still the highly change are observed at extreme negative values

plot(lag2~lagC2,biov1)
lm0=lm(lag~lagC,biov1)
summary(lm0) #we observe a high positive relationship so the corrected lag did not change the pattern of the observed lag=> good
## 
## Call:
## lm(formula = lag ~ lagC, data = biov1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.3871 -0.9069 -0.0191  0.7850  7.9208 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.179997   0.007104   25.34   <2e-16 ***
## lagC        0.943464   0.001152  818.81   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.2 on 29582 degrees of freedom
##   (655 observations deleted due to missingness)
## Multiple R-squared:  0.9577, Adjusted R-squared:  0.9577 
## F-statistic: 6.705e+05 on 1 and 29582 DF,  p-value: < 2.2e-16
par(mfrow=c(1,2))

plot(lag2~velocity,biov1)
lm0=lm(lag2~velocity+I(velocity^2),biov1)
summary(lm0) #significant; R2=46%
## 
## Call:
## lm(formula = lag2 ~ velocity + I(velocity^2), data = biov1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -144.654   -0.356    1.118    2.108    6.504 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -0.895599   0.038423  -23.31   <2e-16 ***
## velocity       0.277031   0.022487   12.32   <2e-16 ***
## I(velocity^2)  0.054080   0.002236   24.18   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.266 on 30236 degrees of freedom
## Multiple R-squared:  0.1873, Adjusted R-squared:  0.1873 
## F-statistic:  3484 on 2 and 30236 DF,  p-value: < 2.2e-16
x1=seq(min(biov1$velocity, na.rm = T),max(biov1$velocity, na.rm = T),le=100)
p1=predict(lm0,newdata=data.frame(velocity=x1),type="response")
points(p1~x1,type="l",col=2,lwd=2) #bimodal relationship

plot(lagC2~velocity,biov1) 
lm0=lm(lagC2~velocity+I(velocity^2),biov1)
summary(lm0)#significant; R2=86
## 
## Call:
## lm(formula = lagC2 ~ velocity + I(velocity^2), data = biov1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -143.281   -0.624    1.177    2.150    6.533 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -1.160582   0.038835  -29.89   <2e-16 ***
## velocity       0.235309   0.022885   10.28   <2e-16 ***
## I(velocity^2)  0.053876   0.002322   23.21   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.227 on 29581 degrees of freedom
##   (655 observations deleted due to missingness)
## Multiple R-squared:  0.1656, Adjusted R-squared:  0.1655 
## F-statistic:  2935 on 2 and 29581 DF,  p-value: < 2.2e-16
x1=seq(min(biov1$velocity, na.rm = T),max(biov1$velocity, na.rm = T),le=100)
p1=predict(lm0,newdata=data.frame(velocity=x1),type="response")
points(p1~x1,type="l",col=2,lwd=2) #bimodal relationship

10 All shifts vs same direction

ggplot(biov1, aes(x = velocity, y = SHIFT))+
    geom_point(aes(color = lag2), alpha = .1)+
    scale_color_viridis_c()+
    geom_smooth(method = "lm")+
    theme_classic()+
    facet_wrap(Param~Type+ECO, scales = "free")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(biov1 %>%
           filter(shift_vel_sign == "pospos" | shift_vel_sign == "negneg"), 
       aes(x = abs(velocity), y = abs(SHIFT)))+
    geom_point(aes(color = lag2), alpha = .1)+
    scale_color_viridis_c()+
    geom_smooth(method = "lm")+
    theme_classic()+
    facet_wrap(Param~Type+ECO, scales = "free")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(biov1, aes(x = velocity, y = SHIFT_cor))+
    geom_point(aes(color = lag2), alpha = .1)+
    scale_color_viridis_c()+
    geom_smooth(method = "lm")+
    theme_classic()+
    facet_wrap(Param~Type+ECO, scales = "free")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 655 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 655 rows containing missing values (`geom_point()`).

ggplot(biov1 %>%
           filter(shift_vel_sign == "pospos" | shift_vel_sign == "negneg"), 
       aes(x = abs(velocity), y = abs(SHIFT_cor)))+
    geom_point(aes(color = lag2), alpha = .1)+
    scale_color_viridis_c()+
    geom_smooth(method = "lm")+
    theme_classic()+
    facet_wrap(Param~Type+ECO, scales = "free")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 259 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 259 rows containing missing values (`geom_point()`).

11 Load genetic data

Datasets used here:

  • Pinsky, unpublished: Microsatellites and mitochondrial DNA Data for marine fishes.

  • De Kort et al. 2021 Nat Comm: Microsatellites and AFPL Used expected heterozygosity as a metric of genetic diversity (GDP). It is directly related to effective population size. Because GDP is very sensitive to marker type (e.g. GDP is restricted between 0 and 0.5 in AFLP markers and between 0 and 1 in microsatellite markers), GDP values from each marker type were standardized (mean = 0 and variance = 1) to make them comparable across studies. Standardized GDP values were then normalized as (GDP_scaled-min)/(max-min) to range from 0 to 1. Data for: plant, amphibian, reptile, bird, mammal, and mollusc.

  • Lawrence et al. 2019 Sci Data: MacroPopGen database. Microsatellites Site-level estimates of genetic diversity from microsatellite markers for vertebrate species (terrestrial vertebrates and freshwater fish) across North and South America. Used FST or expected heterozygosity as a metric of genetic diversity (GDP). Data for: amphibians, birds, fish [anadromous, brackish, catadromous, or freshwater], mammals, and reptiles.

  • Fonseca et al. 2023 Evo Letters: Mitochondrial DNA (for vertebrates, arachnids, and insects. Chloroplast DNA and nucleotide diversity (for plants). (Ï€) was calculated to describe patterns of intraspecific genetic diversity.

  • Canteri et al. 2021 Ecography: (We wont use this data because it has no coordinates) Mitochondrial DNA (mtDNA) cytochrome b diversity. Measured genetic diversity at the species level with nucleotide diversity. Data for 1036 bird species.

# Pinsky mtdna
mt <- fread(here::here('Data/mtdna.csv'))
mt$spp <- Clean_Names(mt$spp,
                      return_gen_sps = TRUE)

# Pinsky msat
ms <- fread(here::here('Data/msat.csv'))
ms$spp <- Clean_Names(ms$spp,
                      return_gen_sps = TRUE)

# De Kort et al. 2021
gen_d <- fread(here::here('Data/Deposited_data_genetic_diversity_dekort2021.csv'))
gen_d$spp <-  gsub("_"," ",gen_d$Species)
gen_d$spp <- Clean_Names(gen_d$spp,
                         return_gen_sps = TRUE)

# Lawrence et al. 2019: MacroPopGen
gen_lf <- read_excel(here::here("Data/MacroPopGen_Database_final-v0.2.xlsx"), sheet = "MacroPopGen_Database")
gen_lf$spp <-  gsub("_"," ",gen_lf$G_s)
gen_lf$spp <- Clean_Names(gen_lf$spp,
                          return_gen_sps = TRUE)

# Fonseca et al. 2023
gen_fon <- fread(here::here("Data/Fonseca_etal_2023_EvoLetters.txt"))
gen_fon$spp <- gen_fon$Species
gen_fon$spp <-  gsub("-"," ",gen_fon$spp)
gen_fon$spp <-  gsub("_"," ",gen_fon$spp)
gen_fon$spp <- Clean_Names(gen_fon$spp,
                           return_gen_sps = TRUE)


# Phenotypic rates
pheno <- fread(here::here('Data/PROCEEDv6_RatesDB.csv'))
pheno$spp <- Clean_Names(pheno$sp_ncbi,
                         return_gen_sps = TRUE)


##############################
# Remove species identified to the genus level or cf. species
all_sps <- unique(c(gen_d$spp,gen_lf$spp,gen_fon$spp,mt$spp,ms$spp,pheno$spp))
length(all_sps)

spgen <- sapply(all_sps, function(x){
    tmp. <- strsplit(x, " ")[[1]]
    any(tmp. == "sp" | tmp. == "spp" | grepl("sp[.]",tmp.) | grepl("spp[.]",tmp.) | tmp. == "cf[.]" | tmp. == "cf" | length(tmp.) == 1 | length(tmp.) > 2)
})
spgen <- which(spgen)
spgen <- all_sps[-spgen]
all(spgen %in% all_sps)

all_sps <- all_sps[which(all_sps %in% spgen)]
length(all_sps) # N species after filtering species identified to the species level

# filter each dataset
gen_d <- gen_d[which(gen_d$spp %in% all_sps),]
gen_lf <- gen_lf[which(gen_lf$spp %in% all_sps),]
gen_fon <- gen_fon[which(gen_fon$spp %in% all_sps),]
mt <- mt[which(mt$spp %in% all_sps),]
ms <- ms[which(ms$spp %in% all_sps),]
pheno <- pheno[which(pheno$spp %in% all_sps),]

length(unique(gen_d$spp)) # 714
length(unique(gen_lf$spp)) # 877
length(unique(gen_fon$spp)) # 35219
length(unique(mt$spp)) # 162
length(unique(ms$spp)) # 275
length(unique(pheno$spp)) # 415

11.1 Fix names at the genetic data

# Species to find
mycols <- c("reported_name_fixed","scientificName","kingdom","phylum","class","order","family","db_code")
sps_accepted_names <- data.frame(matrix(ncol = length(mycols), nrow = length(unique(all_sps))))
names(sps_accepted_names) <- mycols

sps_accepted_names$reported_name_fixed <- unique(all_sps)
tofind_ <- sps_accepted_names[which(is.na(sps_accepted_names$scientificName)),]
tofind_ <- unique(tofind_$reported_name_fixed)

tofind <- data.frame(matrix(nrow = length(tofind_), ncol = 8))
names(tofind) = c("scientificName", "kingdom", "phylum", "class", "order", "family", "db", "db_code")

tofind <- data.frame(species = tofind_, tofind)

tofind <- tofind %>%
    mutate(across(everything(), as.character))


# retrieve sp names
sp_names_found <- Find_Sci_Names(sp_name = tofind$species)

# ----------------
#  Summary 
# ----------------
# 
# N taxa:
# 36697
# N taxa found:
# |db   |     N|
# |:----|-----:|
# |GBIF | 35903|
# |ITIS |    76|
# |NCBI |   278|
# N taxa not found:
# 440


## Add found species names to the sps_accepted_names

all(sp_names_found$requested_name %in% sps_accepted_names$reported_name_fixed)

for(i in 1:length(sp_names_found$requested_name)){
    tofill <- unique(which(sps_accepted_names$reported_name_fixed == sp_names_found$requested_name[i]))
    sps_accepted_names$scientificName[tofill] <- sp_names_found$scientificName[i]
    sps_accepted_names$kingdom[tofill] <- sp_names_found$kingdom[i]
    sps_accepted_names$phylum[tofill] <-sp_names_found$phylum[i]
    sps_accepted_names$class[tofill] <- sp_names_found$class[i]
    sps_accepted_names$order[tofill] <- sp_names_found$order[i]
    sps_accepted_names$family[tofill] <- sp_names_found$family[i]
    sps_accepted_names$db[tofill] <- sp_names_found$db[i]
    sps_accepted_names$db_code[tofill] <- sp_names_found$db_code[i]
    sps_accepted_names$method[tofill] <- sp_names_found$method[i]
}

sps_accepted_names$spp = sps_accepted_names$reported_name_fixed


## Keep original taxa information for those species we could not find a name at GBIF

pos <- which(is.na(sps_accepted_names$scientificName))
sps_accepted_names$scientificName[pos] <- sps_accepted_names$spp[pos]

for(i in 1:nrow(mt)){
    mt$spp_new[i] <- sps_accepted_names$scientificName[which(sps_accepted_names$spp == mt$spp[i])]
}
for(i in 1:nrow(ms)){
    ms$spp_new[i] <- sps_accepted_names$scientificName[which(sps_accepted_names$spp == ms$spp[i])]
}
for(i in 1:nrow(gen_d)){
    gen_d$spp_new[i] <- sps_accepted_names$scientificName[which(sps_accepted_names$spp == gen_d$spp[i])]
}
for(i in 1:nrow(gen_lf)){
    gen_lf$spp_new[i] <- sps_accepted_names$scientificName[which(sps_accepted_names$spp == gen_lf$spp[i])]
}
for(i in 1:nrow(gen_fon)){
    gen_fon$spp_new[i] <- sps_accepted_names$scientificName[which(sps_accepted_names$spp == gen_fon$spp[i])]
}
for(i in 1:nrow(gen_lf)){
    pheno$spp_new[i] <- sps_accepted_names$scientificName[which(sps_accepted_names$spp == pheno$spp[i])]
}

write.csv(mt, 
          here::here('Data/mtdna_harmo.csv'), row.names = FALSE)
write.csv(ms, 
          here::here('Data/msat_harmo.csv'), row.names = FALSE)
write.csv(gen_d, 
          here::here('Data/Deposited_data_genetic_diversity_dekort2021_harmo.csv'), row.names = FALSE)
write.csv(gen_lf, 
          here::here('Data/MacroPopGen_Database_final_areas_Lawrence_Fraser_2020_harmo.csv'), row.names = FALSE)
write.csv(gen_fon, 
          here::here('Data/Fonseca_etal_2023_EvoLetters_harmo.txt'), row.names = FALSE)
write.csv(pheno, 
          here::here('Data/PROCEEDv6_RatesDB_harmo.csv'), row.names = FALSE)

12 Load harmonized genetic data

mt <- fread(here::here('Data/mtdna_harmo.csv'))
ms <- fread(here::here('Data/msat_harmo.csv'))
gen_d <- fread(here::here('Data/Deposited_data_genetic_diversity_dekort2021_harmo.csv'))
gen_lf <- fread(here::here('Data/MacroPopGen_Database_final_areas_Lawrence_Fraser_2020_harmo.csv'))
gen_fon <- fread(here::here('Data/Fonseca_etal_2023_EvoLetters_harmo.txt'))
pheno <- fread(here::here('Data/PROCEEDv6_RatesDB_harmo.csv'))

12.1 Stats

# Gen
gen_sps <- unique(c(mt$spp_new, ms$spp_new, gen_d$spp_new, gen_lf$spp_new, gen_lf$spp_new, gen_fon$spp_new))

bsi_v1 <- intersect(biov1$spp, gen_sps)

# Break down
tot1 <- data.frame(N_species_with_gen_data = length(gen_sps),
                   v1_matches = length(bsi_v1))
tot1
##   N_species_with_gen_data v1_matches
## 1                   36016       3145
# N_species_with_gen_data v1_matches
#                    36016       3145

# phenotypic
phen_sps <- unique(pheno$spp_new)

bsj_v1 <- intersect(biov1$spp, phen_sps)

# Break down
tot2 <- data.frame(N_species_with_pheno_data = length(phen_sps),
                   v1_matches = length(bsj_v1))
tot2
##   N_species_with_pheno_data v1_matches
## 1                       411        269
#   N_species_with_pheno_data v1_matches
#                       411        269

12.2 Explore distribution

# Malin
ggplot(mt, aes(He)) +
    geom_histogram() +
    ggtitle("Malin's Mitochondrial")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 48 rows containing non-finite values (`stat_bin()`).

ggplot(ms, aes(He)) +
    geom_histogram() +
    ggtitle("Malin's Microsatellite")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# De Kort
ggplot(gen_d, aes(GDp)) +
    geom_histogram() +
    ggtitle("De Kort AFLP & Microsatellite")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Why De Kort data has the two peaks? It is due to the marker type
ggplot(gen_d, aes(GDp)) +
    geom_histogram()+
    facet_grid(.~Marker)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# But if we look at the normalized GDp, the problem is solved. Therefore, we should be using the normalized version of GDp from DeKort
ggplot(gen_d, aes(GDp_norm)) +
    geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Lawrence & Fraser
ggplot(gen_lf, aes(as.numeric(He))) +
    geom_histogram()+
    ggtitle("Lawrence & Fraser Microsatellite")
## Warning in FUN(X[[i]], ...): NAs introduced by coercion
## Warning in FUN(X[[i]], ...): NAs introduced by coercion
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 1282 rows containing non-finite values (`stat_bin()`).

# Fonseca et al.
ggplot(gen_fon, aes(as.numeric(Nucleotide_diversity))) +
    geom_histogram()+
    ggtitle("Fonseca et al. Mitochondrial DNA")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

13 Create a single genetic diversity dataset

# Malin
mt_sub <- mt  %>%
    mutate(long = as.numeric(lon),
           lat = as.numeric(lat),
           N = as.numeric(n), # Sample size
           Marker = "Mitochondrial DNA")  %>%
    dplyr::filter(!is.na(He) | !He==0) %>%
    dplyr::select(spp, He, long, lat, Marker)
mt_sub$Source = "Malin"
# mt_sub$Het_type = "He"

ms_sub <- ms %>%
    mutate(long = as.numeric(lon),
           lat = as.numeric(lat),
           N = as.numeric(n), # Sample size
           Marker = "Microsatellite")  %>%
    dplyr::filter(!is.na(He) | !He==0) %>%
    dplyr::select(spp, He, long, lat, Marker)
ms_sub$Source = "Malin"
# ms_sub$Het_type = "He"

###################
# De Kort

# Jonathan R.:
# co-dominant refers to the fact that you can distinguish homozigous and heterozygous individuals, such as microsatellites
# dominant means that you either have the detection of the marker or not. but you don’t know if the individual is heterozygous or not, such as AFLP
# restriction enzymes are proteins that you use to cut the genomes into fragments. there are used for AFLP and allozymes, so not sure

# De Kort code for Marker:
# CD = Co-dominant
# D = Dominant
# ENZ = Enzime

gen_d_sub <- gen_d %>%
    mutate(long = as.numeric(LONGITUDE),
           lat = as.numeric(LATITUDE),
           spp = spp_new, 
           He = as.numeric(GDp),
           N = as.numeric(SampleSize), # Sample size
           Marker = case_when(
               Marker=="CD" ~ "Microsatellite",
               Marker=="D" ~ "AFLP",
               Marker=="ENZ" ~ "AFLP",
               TRUE ~ as.character(Marker))) %>%
    dplyr::filter(!is.na(He) | !He==0) %>%
    dplyr::filter(!(Marker == "AFLP" & He > .5)) %>% # AFLPs > 0.5 are errors
    dplyr::select(spp, He, long, lat, Marker)
gen_d_sub$Source = "De Kort"
# gen_d_sub$Het_type = "He"

# How DeKort calculated the normalized version of GDp
# gen_d_sub$He_harm <- NA
# 
# m <- unique(gen_d_sub$Marker)
# for(i in 1:length(m)){
# pos <- which(gen_d_sub$Marker == m[i])
# gen_d_sub$He_harm[pos] <-  scale(gen_d_sub$He[pos])
# }
# gen_d_sub$He_harm <-  (gen_d_sub$He_harm - min(gen_d_sub$He_harm))/(max(gen_d_sub$He_harm)-min(gen_d_sub$He_harm))

###################
# Lawrence & Fraser
gen_lf$He <- as.numeric(gen_lf$He)
## Warning: NAs introduced by coercion
gen_lf$Ho <- as.numeric(gen_lf$Ho)
## Warning: NAs introduced by coercion
pos <- which(is.na(gen_lf$He))
gen_lf$He_new <- gen_lf$He
gen_lf$He_new[pos] <- gen_lf$Ho[pos]
# gen_lf$Het_type = "He"
# gen_lf$Het_type[pos] = "Ho"

gen_lf_sub <- gen_lf %>%
    mutate(long = as.numeric(Long),
           lat = as.numeric(Lat),
           He = as.numeric(He_new),
           spp = spp_new,
           N = as.numeric(n), # Sample size
           Marker = "Microsatellite") %>% 
    dplyr::filter(!is.na(He) | !He==0) %>%
    dplyr::select(spp, He, long, lat, Marker, 
                  # Het_type
                  ) 
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `N = as.numeric(n)`.
## Caused by warning:
## ! NAs introduced by coercion
gen_lf_sub$Source = "Lawrence & Fraser"

###################
# Fonseca et al.
gen_fon_sub <- gen_fon  %>%
    mutate(long = as.numeric(Longitude),
           lat = as.numeric(Latitude),
           He = Nucleotide_diversity)  %>%
    dplyr::filter(!is.na(Nucleotide_diversity) | !Nucleotide_diversity==0) %>%
    dplyr::select(spp, He, long, lat)
gen_fon_sub$Source = "Fonseca"
gen_fon_sub$Marker = "Mitochondrial DNA"

###################
# Group all
gen_div <- rbind(mt_sub %>% dplyr::select(names(mt_sub)), 
                 ms_sub %>% dplyr::select(names(mt_sub)),
                 gen_d_sub %>% dplyr::select(names(mt_sub)),
                 gen_lf_sub %>% dplyr::select(names(mt_sub)),
                 gen_fon_sub %>% dplyr::select(names(mt_sub)))
gen_div <- na.omit(gen_div)

gen_div$spp <- as.factor(gen_div$spp)
gen_div$Marker <- as.factor(gen_div$Marker)
gen_div$Source <- as.factor(gen_div$Source)

14 Harmonize genetic data

  • He_harm: transformation used by DeKort et al 2021 (Nature Communications). Makes markers range from 0-1.
  1. scale values at each marker type
  2. standardize (x - min)/(max-min)
  • He_harm2: transformation suggested by Malin. Applies the function transform01 before a logit transformation.
  1. transform01 />/> Moves He values slightly inward so that a logit transformation is possible.
  2. apply logit transformation
  • He_harm3: He_harm2 centered in zero.
gen_div$He_harm <- NA
gen_div$He_harm2 <- NA
gen_div$He_harm3 <- NA

m <- unique(gen_div$Marker)
for(i in 1:length(m)){
    # Select marker type
    pos <- which(gen_div$Marker == m[i])
    # Apply DeKort transformation
    gen_div$He_harm[pos] <- deKort_trans(gen_div$He[pos])
    # Apply logit transformation
    gen_div$He_harm2[pos] <- logit_trans(gen_div$He[pos])
    # Centered in zero
    gen_div$He_harm3[pos] <- scale(gen_div$He_harm2[pos])
}

# Filter the species in Bioshifts
gen_div <- gen_div %>% dplyr::filter(spp %in% unique(biov1$spp))

# remove outliers
gen_metrics <- c("He_harm","He_harm2","He_harm3")

for (i in 1:length(gen_metrics)){
    my_gem <- as.numeric(data.frame(gen_div %>% select(gen_metrics[i]))[,1])
    
    quartiles <- quantile(my_gem, probs=c(.05, .95), na.rm = FALSE)
    IQR <- IQR(my_gem)
    
    Lower <- quartiles[1] - 1.5*IQR
    Upper <- quartiles[2] + 1.5*IQR 
    
    gen_div <- subset(gen_div, my_gem > Lower & my_gem < Upper)
}

14.1 Avg by location

We averaged genetic diversity by location (same species, in the same XY coordinates)

# How many species with >1 gen div measurements at the same site?
# Check how many obs per site and marker type exist
N_obs <- gen_div %>%
    group_by(spp, long, lat) %>%
    tally() %>%
    dplyr::filter(n>1)

DT::datatable(N_obs)
## Warning in instance$preRenderHook(instance): It seems your data is too big for
## client-side DataTables. You may consider server-side processing:
## https://rstudio.github.io/DT/server.html
# Is there any species with >1 marker type in the same location?
gen_div %>%
    group_by(spp, long, lat, Marker) %>%
    dplyr::summarise(N = length(unique(spp))) %>%
    dplyr::filter(N>1)
## `summarise()` has grouped output by 'spp', 'long', 'lat'. You can override
## using the `.groups` argument.
## # A tibble: 0 × 5
## # Groups:   spp, long, lat [0]
## # ℹ 5 variables: spp <fct>, long <dbl>, lat <dbl>, Marker <fct>, N <int>
# No, there are not

# Is there any species with >1 Source type in the same location?
gen_div %>%
    group_by(spp, long, lat, Source) %>%
    dplyr::summarise(N = length(unique(spp))) %>%
    dplyr::filter(N>1)
## `summarise()` has grouped output by 'spp', 'long', 'lat'. You can override
## using the `.groups` argument.
## # A tibble: 0 × 5
## # Groups:   spp, long, lat [0]
## # ℹ 5 variables: spp <fct>, long <dbl>, lat <dbl>, Source <fct>, N <int>
# No, there are not

# Avg by site and species
gen_div <- gen_div %>%
    group_by(spp, long, lat) %>%
    dplyr::summarise(He = median(He),
                     He_harm = median(He_harm),
                     He_harm2 = median(He_harm2),
                     He_harm3 = median(He_harm3),
                     Source = paste(Source, sep = ", "),
                     Marker = paste(Marker, sep = ", "))
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'spp', 'long', 'lat'. You can override
## using the `.groups` argument.
unique(gen_div$Source)
## [1] "Fonseca"           "De Kort"           "Lawrence & Fraser"
## [4] "Malin"
unique(gen_div$Marker)
## [1] "Mitochondrial DNA" "AFLP"              "Microsatellite"

14.2 Which species?

gen_div <- merge(gen_div, 
                 splist[,-7],
                 by.x="spp",
                 by.y="scientificName",
                 all.x = T)

toplot_ <- gen_div %>%
    group_by(Group) %>%
    dplyr::summarise(Obs = length(spp),
                     Species = length(unique(spp))) %>%
    gather(var, N, -c(Group))

ggplot(toplot_, aes(x = Group, y = N))+
    ggtitle("N species by Group")+
    geom_bar(stat="identity")+
    geom_text(aes(y=N, label=N, 
                  hjust = ifelse(N<max(N),-.1,1.1)), vjust=0.2, size=3, 
              position = position_dodge(0.9))+
    theme_classic()+
    coord_flip()+
    facet_wrap(.~var, scales = "free", ncol=1)

14.3 Distribution of He

# correlations
ggpairs(gen_div,
        columns = c("He","He_harm","He_harm2","He_harm3"))

ggpairs(gen_div,
        columns = c("He","He_harm","He_harm2","He_harm3"),      
        aes(color = Marker,  
            alpha = 0.5))     

ggpairs(gen_div,
        columns = c("He","He_harm","He_harm2","He_harm3"),      
        aes(color = Source,  
            alpha = 0.5))

to_plot <- gen_div %>%
    select(Group,He_harm,He_harm2,He_harm3) %>%
    filter(Group %in% c("Mammal","Fish","Plant", "Bird")) %>%
    gather(metric, value, -Group)

ggplot(to_plot, aes(value, fill = Group, color = Group))+
    geom_density(alpha = .3)+
    scale_color_viridis_d()+
    scale_fill_viridis_d()+
    facet_wrap(.~metric, scales = "free")

14.4 High He with latitude?

14.4.1 Absolution latitude

toplot <- gen_div %>%
    mutate(Hemisphere = ifelse(lat<0, "South", "North"),
           lat_abs = abs(lat),
           He_harm = scale(He_harm),
           He_harm3 = scale(He_harm3))

ggplot(toplot, aes(x = lat_abs, y = He_harm, color = Group))+
    geom_point(alpha = .1)+
    stat_smooth(method = "lm")+
    facet_wrap(.~Group,scales = "free")
## `geom_smooth()` using formula = 'y ~ x'

mod1 <- lm(He_harm~lat*Group, toplot)
emtrends(mod1, ~ lat*Group, var = "lat")
##   lat Group                               lat.trend       SE    df  lower.CL
##  46.4 Amphibian                            0.004164 0.002302 11085 -0.000348
##  46.4 Ascidians tunicates and sea squirts    nonEst       NA    NA        NA
##  46.4 Bird                                 0.004774 0.000767 11085  0.003271
##  46.4 Fish                                 0.012919 0.000580 11085  0.011783
##  46.4 Insect                               0.000214 0.001010 11085 -0.001765
##  46.4 Mammal                              -0.001732 0.002550 11085 -0.006731
##  46.4 Molluscs                             0.040404 0.145179 11085 -0.244172
##  46.4 Plant                               -0.010242 0.000778 11085 -0.011768
##  46.4 Reptile                             -0.011657 0.015071 11085 -0.041199
##  46.4 Spider                              -0.000195 0.008215 11085 -0.016299
##  upper.CL
##   0.00868
##        NA
##   0.00628
##   0.01406
##   0.00219
##   0.00327
##   0.32498
##  -0.00872
##   0.01789
##   0.01591
## 
## Confidence level used: 0.95

14.5 Spatial pattern

mundi <- terra::vect(rnaturalearth::ne_coastline(scale = 110, returnclass = "sp"))
## Warning: The `returnclass` argument of `ne_download()` sp as of rnaturalearth 1.0.0.
## ℹ Please use `sf` objects with {rnaturalearth}, support for Spatial objects
##   (sp) will be removed in a future release of the package.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# get vect gen div
vect_div <- terra::vect(gen_div,geom=c("long","lat"),crs=crs(mundi))

# get vect centroids bioshifts
vect_biov1 <- terra::vect(biov1 %>%
                              filter(spp %in% gen_div$spp),
                          geom=c("centroid.x","centroid.y"),crs=crs(mundi))

# get raster bioshifts shp files study areas
get_raster_bioshifts = "NO"
if(get_raster_bioshifts=="YES"){
    my_ext = terra::ext(mundi)
    my_crs = crs(mundi)
    rast_biov1 <- terra::rast(my_ext, crs = my_crs, res = 0.5)
    values(rast_biov1) <- 0
    
    fgdb <- "C:/Users/brunn/ShadowDrive/CreateGeodatabaseBioShifts/Data/ShapefilesBioShiftsv3"
    fc_list <- list.files(fgdb,pattern = ".shp")
    fc_list <- gsub(".shp","",fc_list)
    fc_list <- fc_list[which(fc_list %in% unique(as.data.frame(vect_biov1)$ID))]
    
    for(i in 1:length(fc_list)){ cat("\r",i,"from",length(fc_list))
        tmp = terra::vect(here::here(fgdb, paste0(fc_list[i],".shp")))
        tmp = terra::cells(rast_biov1,tmp)
        tmp_cell = tmp[,2]
        tmp_vals = rast_biov1[tmp_cell][,1]
        rast_biov1[tmp_cell] = tmp_vals+1
    }
    names(rast_biov1) <- "SA"
    rast_biov1[rast_biov1==0] <- NA
    
    writeRaster(rast_biov1, here::here("Data/raster_bioshifts_SA.tif"), overwrite = TRUE)
    
} else {
    rast_biov1 <- terra::rast(here::here("Data/raster_bioshifts_SA.tif"))
}

values_biov1 <- na.omit(values(rast_biov1))

ggplot()+
    ggtitle("Genetic diversity data")+
    geom_spatvector(data=mundi)+
    geom_spatvector(data=vect_div,aes(color = Marker))+
    theme_blank()

ggplot()+
    ggtitle("Genetic diversity data")+
    geom_spatvector(data=mundi)+
    geom_spatvector(data=vect_div,aes(color = Source))+
    theme_blank()

ggplot()+
    ggtitle("Bioshifts data \n(Centroid of study areas)")+
    geom_spatvector(data=mundi)+
    geom_spatvector(data=vect_biov1, aes(color = ECO))+
    theme_blank()

ggplot()+
    ggtitle("Bioshifts data \n(Overlap study areas)")+
    geom_spatraster(data=rast_biov1)+
    scale_fill_whitebox_b(
        palette = "muted",
        na.value = "white",
        breaks = seq(min(values_biov1), max(values_biov1), 1))+
    geom_spatvector(data=vect_biov1, aes(color = ECO))+
    geom_spatvector(data=mundi)+
    theme_blank()

15 Phenotypic rates

pheno_rate <- pheno %>%
    mutate(long = as.numeric(sample1.longitude),
           lat = as.numeric(sample1.latitude),
           trait1 = as.numeric(mean1),
           trait2 = as.numeric(mean2),
           spp = spp_new,
           Trait = trait_type, 
           Years = as.numeric(years),
           Gen = as.numeric(generations)) %>% 
    dplyr::select(spp, long, lat, Trait, trait1, trait2, Years, Gen) %>%
    dplyr::filter(!is.na(trait1) & !is.na(trait2))
pheno_rate$Source = "PROCEED"

15.1 Calculate rate & harmozine

for(i in 1:nrow(pheno_rate)){
    sppi <- pheno_rate$spp[i]
    traiti <- pheno_rate$Trait[i]
    pos_spp_trait_i <- which(pheno_rate$spp == sppi & pheno_rate$Trait == traiti)
    pheno_rate$PR1[i] <- (pheno_rate$trait2[i] - pheno_rate$trait1[i]) / mean(c(pheno_rate$trait2[pos_spp_trait_i], pheno_rate$trait1[pos_spp_trait_i])) * pheno_rate$Years[i]
    pheno_rate$PR2[i] <- (pheno_rate$trait2[i] - pheno_rate$trait1[i]) / sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i], pheno_rate$trait1[pos_spp_trait_i])))^2 * pheno_rate$Years[i]
}
## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced

## Warning in sqrt(mean(c(pheno_rate$trait2[pos_spp_trait_i],
## pheno_rate$trait1[pos_spp_trait_i]))): NaNs produced
pheno_rate$PR_harm <- NA

m <- unique(pheno_rate$Trait)
for(i in 1:length(m)){
    pos <- which(pheno_rate$Trait == m[i])
    # DeKort
    p <- scale(pheno_rate$PR1[pos])
    p <- (p - min(p, na.rm = T))/(max(p, na.rm = T)-min(p, na.rm = T))
    pheno_rate$PR_harm[pos] <-  p
}

# gen_div %>%
# group_by(spp) %>%
# tally() %>%
# summary()

15.2 Distribution of pheno rates

# Look into phenotic rates
ggplot(pheno_rate, aes(PR1)) +
    geom_histogram() +
    facet_wrap(Trait~., scales = "free") +
    ggtitle("Raw data")
## Warning: Removed 1 rows containing non-finite values (`stat_bin()`).

ggplot(pheno_rate, aes(PR_harm)) +
    geom_histogram() +
    facet_wrap(Trait~., scales = "free") +
    ggtitle("Harmonization following De Kort")
## Warning: Removed 1 rows containing non-finite values (`stat_bin()`).

16 Merge genetic and bioshifts data

We tried several methods for merging genetic data and bioshifts.

  • Method 1: Normal merge Uses the merge function to aggregate bioshifts and gen div data. This creates multiple false duplicates.

  • Method 2: Median He per species. This ignores spatial proximity of He values to range shift values.

  • Method 3: Median He per Param & species Use lower latitude TE and higher latitude as LE (North Hemisphere). Although this collects He values based on latitude, the proximity of He to the study areas where range shifts were observed is ignored.

  • Method 4: Distance based approach. Calculates distance weighted mean of He to the centroid of the study area.

  • Method 5: Location based approach. Get the closest He to the centroid (for centroid shift), to the max latitude (for LE shift, at the North hemisphere), and to the min latitude (for TE shift, at the North hemisphere) of the study area.

We decided that Method 5 is the best one.

17 Method 1 - Normal merge

This is not the correct way to merge because it creates multiple false duplicates.

18 Method 2 - Median He per species

This ignores spatial proximity of He values to range shift values.

gen_div_avg <- gen_div %>%
    group_by(spp) %>%
    dplyr::summarise(N = length(spp),
                     He_harm = median(He_harm),
                     He_harm2 = median(He_harm2),
                     He_harm3 = median(He_harm3)) 

#merge all data frames in list
gen_data_v1_avg <- append(list(gen_div_avg), list(biov1)) %>% reduce(full_join, by='spp')
gen_data_v1_avg <- gen_data_v1_avg %>% dplyr::filter(!is.na(He_harm), !is.na(SHIFT))

# N species
length(unique(gen_data_v1_avg$spp))
## [1] 3186

18.1 Save data

write.csv(gen_data_v1_avg,here::here("Data/gen_data_final_m2.csv"),row.names = FALSE)

19 Method 3 - Median He per Param & species

Use lower latitude TE and higher latitude as LE (North Hemisphere)./ Although this collects He values based on latitude, the proximity of He to the study areas where range shifts were observed is ignored.

20 Method 4 - Based on distance

Calculate distance weighted mean He for each species in the bioshifts database./ This method collects He values more close to the centroid of the study area.

21 Method 5 - Based on location

Get the closest He to the centroid (for O), to the max latitude (for LE, at the North hemisphere), and to the min latitude (for TE, at the North hemisphere) of the study area.

# sp list
m <- unique(biov1$spp[which(biov1$spp %in% gen_div$spp)])

gen_data_v1_dist2 <- data.frame()

# sp2go="Alces alces"
# sp2go="Sylvia atricapilla"
for(i in 1:length(m)){ cat(i, "from", length(m), "\r")
    sp2go <- m[i]
    
    # subset genetic data
    sub_gen <- subset(gen_div[,1:9], spp == sp2go)
    sub_gen_v <- terra::vect(sub_gen, 
                             geom=c("long", "lat"), 
                             crs = "+proj=longlat +datum=WGS84 +no_defs")
    
    # subset bioshifts data
    sub_bio <- subset(biov1, spp == sp2go)
    
    # study areas for species i
    areas <- unique(sub_bio$ID)
    
    gen_data_v1_dist2_tmp <- data.frame()
    
    # get genetic data for species i in each study area
    for(j in 1:nrow(sub_bio)){
        
        # bioshifts in study area j and range pos r
        sub_bio_area_j_tmp <- sub_bio[j,]
        
        range_pos2go <- sub_bio_area_j_tmp$Param
        
        coord_names <- NA
        coord_names <- if(range_pos2go == "O"){ c("centroid.x", "centroid.y") } else {coord_names}
        coord_names <- if(range_pos2go == "LE" & sub_bio_area_j_tmp$centroid.y > 0){ c("max_lat.x", "max_lat.y") } else {coord_names}
        coord_names <- if(range_pos2go == "LE" & sub_bio_area_j_tmp$centroid.y < 0){ c("min_lat.x", "min_lat.y") } else {coord_names}
        coord_names <- if(range_pos2go == "TE" & sub_bio_area_j_tmp$centroid.y < 0){ c("max_lat.x", "max_lat.y") } else {coord_names}
        coord_names <- if(range_pos2go == "TE" & sub_bio_area_j_tmp$centroid.y > 0){ c("min_lat.x", "min_lat.y") } else {coord_names}
        
        sub_bio_area_j_v = data.frame(sub_bio_area_j_tmp)[,coord_names]
        names(sub_bio_area_j_v) <- c("long", "lat")
        
        sub_bio_area_j_v <- terra::vect(unique(sub_bio_area_j_v[,c("long", "lat")]), 
                                        geom=c("long", "lat"), 
                                        crs = "+proj=longlat +datum=WGS84 +no_defs")
        
        # plot(terra::vect(rbind(sub_gen[,c("long", "lat")], sub_bio_area_j_tmp[,c("long", "lat")]),
        #  geom=c("long", "lat"),
        #  crs = "+proj=longlat +datum=WGS84 +no_defs"))
        # plot(sub_bio_area_j_v, col = "red", add=T)
        
        dists <- terra::distance(sub_bio_area_j_v, sub_gen_v)[1,]
        dists_order <- order(dists)[1]
        min_dist <- dists[dists_order] # distance to closest
        
        # the closest
        sub_gen_tmp <- sub_gen[dists_order,]
        sub_gen_tmp$min_dist <- min_dist
        
        # weighted distance
        sub_gen_tmp$He_harm_w <- weighted.mean(sub_gen$He_harm, 1/(dists^2)) # inverse of the distance
        sub_gen_tmp$He_harm2_w <- weighted.mean(sub_gen$He_harm2, 1/(dists^2)) # inverse of the distance
        sub_gen_tmp$He_harm3_w <- weighted.mean(sub_gen$He_harm3, 1/(dists^2)) # inverse of the distance
        
        gen_data_v1_dist2_tmp <- rbind(gen_data_v1_dist2_tmp,
                                       append(list(sub_gen_tmp), 
                                              list(sub_bio_area_j_tmp)) %>%
                                           reduce(full_join, by="spp"))
        
    }
    
    gen_data_v1_dist2 <- rbind(gen_data_v1_dist2,
                               gen_data_v1_dist2_tmp)
    
}

gen_data_v1_dist2 <- gen_data_v1_dist2 %>% dplyr::filter(!is.na(He), !is.na(SHIFT))

21.1 Save data

write.csv(gen_data_v1_dist2,here::here("Data/gen_data_final_m5.csv"),row.names = FALSE)

22 Explore data

# n range shifts
nrow(gen_data_v1_dist2)
## [1] 11849
# n genetic diversity measurements (after averaging by location)
dim(gen_div)
## [1] 11104    17

22.1 The closest He vs distance weighted He

plot(gen_data_v1_dist2$He_harm,gen_data_v1_dist2$He_harm_w)

plot(gen_data_v1_dist2$He_harm2,gen_data_v1_dist2$He_harm2_w)

plot(gen_data_v1_dist2$He_harm3,gen_data_v1_dist2$He_harm3_w)

22.2 Which species?

# N species
length(unique(gen_data_v1_dist2$spp))
## [1] 3186
# Use only plus plus or minus minus
table(gen_data_v1_dist2$shift_vel_sign)
## 
## negneg negpos posneg pospos 
##    203   4393    297   6956
# N species
length(unique(gen_data_v1_dist2$spp))
## [1] 3186
toplot_ <- gen_data_v1_dist2 %>%
    group_by(Group) %>%
    dplyr::summarise(Species = length(unique(spp)),
                     Obs = length(spp))

toplot_ <- reshape2::melt(toplot_)
## Using Group as id variables
ggplot(toplot_, aes(x = Group, y = value))+
    geom_bar(stat="identity")+
    geom_text(aes(y=value, label=value), 
              hjust = -.1, vjust=0.2, size=3, 
              position = position_dodge(0.9))+
    theme_classic()+
    coord_flip()+
    facet_wrap(.~variable, scales = "free", ncol = 1)

22.3 Compare lag values of the full bioshifts vs the subset (genetic) dataset

toplot <- rbind(
    data.frame(dataset = "Full", 
               lags = biov1$lag2, 
               shifts = biov1$SHIFT),
    data.frame(dataset = "Subset", 
               lags = gen_data_v1_dist2$lag2, 
               shifts = gen_data_v1_dist2$SHIFT))

# lags
ggplot(toplot, aes(x = dataset, y=lags, fill = dataset, color = dataset))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    scale_y_continuous(limits = quantile(toplot$lags, c(0.1, 0.9), na.rm = T))
## Warning: Removed 8175 rows containing non-finite values (`stat_boxplot()`).

tapply(toplot$lags, toplot$dataset, summary)
## $Full
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## -145.1653   -0.4280    0.5907    0.3604    2.1868   13.1259 
## 
## $Subset
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## -145.1653   -0.8960    0.5397    0.1183    2.1601   13.1259
mod1 <- aov(lags~dataset, data = toplot)
summary(mod1)
##                Df Sum Sq Mean Sq F value   Pr(>F)    
## dataset         1    499   498.9   21.84 2.98e-06 ***
## Residuals   42086 961660    22.8                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# shift
ggplot(toplot, aes(x = dataset, y=shifts, fill = dataset, color = dataset))+
    geom_boxplot(alpha = .5, outlier.shape = NA)+
    scale_y_continuous(limits = quantile(toplot$shifts, c(0.1, 0.9), na.rm = T))
## Warning: Removed 8416 rows containing non-finite values (`stat_boxplot()`).

tapply(toplot$shifts, toplot$dataset, summary)
## $Full
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## -119.1696   -0.4362    0.2917    1.1682    2.4222  146.3000 
## 
## $Subset
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## -119.1696   -0.3014    0.3705    1.3252    2.6621  146.3000
mod1 <- aov(shifts~dataset, data = toplot)
summary(mod1)
##                Df  Sum Sq Mean Sq F value  Pr(>F)   
## dataset         1     210  209.92   6.866 0.00879 **
## Residuals   42086 1286656   30.57                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

There are difference in mean values of lags, but no difference in mean shift values, between the full and subset datasets.

22.4 Lag

22.4.1 General pattern

22.4.1.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3, aes(color = SHIFT_abs))+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.1.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.1.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.2 By Param

22.4.2.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.2.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.2.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.3 By Group

22.4.3.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.3.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.3.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.4 By Group /* Param

22.4.4.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.4.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.4.4.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5 Lag 2

22.5.1 General pattern

22.5.1.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.1.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.1.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.2 By Param

22.5.2.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.2.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.2.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.3 By Group

22.5.3.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.3.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.3.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.4 By Group /* Param

22.5.4.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.4.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.5.4.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = lagC2, color = SHIFT_abs))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("lagC (Velocity - Shift)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6 SHIFT

22.6.1 General pattern

22.6.1.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.1.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.1.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.2 By Param

22.6.2.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.2.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = log1p(sqrt(abs(SHIFT_cor))), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = log1p(sqrt(abs(SHIFT_cor))), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.2.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Param, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.3 By Group

22.6.3.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.3.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.3.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(.~Group, scales = "free", ncol = 3)
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.4 By Group /* Param

22.6.4.1 He_harm

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm, y = (abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm, y = (abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.4.2 He_harm2

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm2, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm2, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_wrap(Param~Group, scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).

22.6.4.3 He_harm3

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "LAT") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Latitude")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 146 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 146 rows containing missing values (`geom_point()`).

gen_data_v1_dist2 %>%
    dplyr::filter(Type == "ELE") %>%
    ggplot(aes(x = He_harm3, y = sqrt(abs(SHIFT_cor)), color = lag))+
    ggtitle("Elevation")+
    xlab("Genetic diversity (He harm logit)")+
    ylab("Range shift (km/year)") +
    scale_color_viridis_c(direction = -1)+
    geom_point(alpha = .5, size = 3)+
    theme_bw()+
    geom_smooth(method = "lm", color = "black", size=1)+
    stat_smooth(geom="line", method = "lm", alpha=0.3, se = FALSE, 
                aes(by=as.factor(Article_ID)), color = "black")+
    facet_grid(Group~Param,scales = "free")
## Warning in stat_smooth(geom = "line", method = "lm", alpha = 0.3, se = FALSE, :
## Ignoring unknown aesthetics: by
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 15 rows containing missing values (`geom_point()`).